let layer = layui.layer
function hr() {
    $.ajax({
        url: 'admin/swipers',
        success: function (res) {
            if (res.status === 0) {
                var tags = template('table-tpl', res)
                $('tbody').html(tags)
            }
        }
    })
}
hr()

$('tbody').on('click', '.layui-badge', function () {
    let id = $(this).attr('data-id')
    let status = $(this).attr('data-status')

    $.ajax({
        url: 'admin/swipers/' + id,
        type: 'PUT',
        data: {
            status
        },
        success: function (res) {
            if (res.status === 0) {
                layer.msg(res.message)
                hr()
            }
        }
    })
})




$('#uploadSwiper').on('click', function () {
    $('#myfile').click()


})


$('#myfile').on('change', function (e) {
    let obj = e.target.files
    let fd = new FormData()
    $.each(obj, (index, item) => {
        fd.append('swipers', item)
    });

    $.ajax({
        url: 'admin/swipers',
        type: 'post',
        processData: false,
        contentType: false,
        data: fd,
        success: function (res) {
            if (res.status === 0) {

                hr()
            }
        }
    })
})








$('tbody').on('click', '.layui-btn', function (res) {
    let id = $(this).attr('data-id')
    layer.confirm('是否确认删除', function (index) {
        $.ajax({
            url: "admin/swipers/" + id,
            type: 'DELETE',
            success: function (res) {
                if (res.status === 0) {
                    layer.close(index);
                    hr()
                }
            }
        })

    });

})